package helloword;

import com.rabbitmq.client.*;
import org.junit.Test;
import utils.ConnectionUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author xj
 * @create 2021/8/11 23:12
 */
public class ReceiveMsg {
    public static void main(String[] args) throws IOException, TimeoutException {

        Connection connection = ConnectionUtils.getConnection("localhost", 5672, "/xj", "xj", "123");
        Channel channel = connection.createChannel();

        channel.queueDeclare("hello", false, false, false, null);

            channel.basicConsume("hello", true, new DefaultConsumer(channel){
                @Override
                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                    System.out.println("new String(body) = " + new String(body));
                }
            });

//            channel.close();
//            connection.close();


    }
}
